package com.hengyi.pda.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.utils.EmptyUtils;
import com.common.utils.SPUtils;
import com.hengyi.pda.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ModiFyNumActivity extends BaseMvpActivity {
    @BindView(R.id.et_old)
    EditText etOld;
    @BindView(R.id.et_new)
    EditText etNew;
    @BindView(R.id.tv_quary)
    TextView tvQuary;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_danhao;
    }

    @Override
    protected void onViewCreated() {

    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(tvQuary);
    }

    @Override
    protected void onViewClicked(View view) {
        if(view.getId()==tvQuary.getId()){
            if(EmptyUtils.isEmpty(getEditTextStr(etNew))||EmptyUtils.isEmpty(getEditTextStr(etOld))){
                showToastMsg("请输入完整信息");
                return;
            }
            if(EmptyUtils.isEmpty(SPUtils.getShareString("00"+getEditTextStr(etOld)+"query"))){
                showToastMsg("该单号没有再该扫码枪保存过");
            }else {
                String q1 = SPUtils.getShareString("00" + getEditTextStr(etOld) + "query");
             String  newQ1  =      q1.replaceAll("00" + getEditTextStr(etOld),"00"+getEditTextStr(etNew));
                SPUtils.setShareString("00"+getEditTextStr(etNew)+"query",newQ1);
                String s1 = SPUtils.getShareString("00" + getEditTextStr(etOld) + "submit");
                String  news1  =        s1.replaceAll("00" + getEditTextStr(etOld),"00"+getEditTextStr(etNew));
                SPUtils.setShareString("00"+getEditTextStr(etNew)+"submit",news1);
                showToastMsg("更换成功");
                onBackPressed();
            }
        }
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("更换销售单号");
    }


    @Override
    public void bindKnife() {
        ButterKnife.bind(this);

    }
}
